package cn.ihna.demo.client.http;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.FullHttpResponse;

import java.nio.charset.StandardCharsets;

/**
 * @author xianyingda@gmail.com
 * @serial
 * @since 2020-08-16 13:05
 */
public class HttpClientInboundHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        FullHttpResponse httpResponse = (FullHttpResponse) msg;
        System.out.println(httpResponse.headers());
        ByteBuf content = httpResponse.content();
        String body = content.toString(StandardCharsets.UTF_8);
        System.out.println("body = " + body);
        httpResponse.release();
    }
}
